/*
package com.atguigu.controller;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;


import java.io.File;

     */
/**
       * @Author Ctrl`
       * @Since 2020/10/16
       *
       *//*



    public class GitController {

        private String localPath;
        private Repository localRepo;
        private Git git;



         public static void main(String[] args) {
             new GitController().download("repo2/","https://gitee.com/xia-xueqiu/repo2.git","master");
         }


         */
/**
          * git代码下载
          *//*


        public String download(String projectName, String gitUrl,String branch) {
            if(StringUtils.isBlank(gitUrl)){
                return "git仓库地址不能为空";
            }
            //认证凭据
            UsernamePasswordCredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider("xia-xueqiu","asdf19910419");
            try {
                //代码指定存储目录
                localPath = "E:\\git_repository" + File.separator + projectName;
                System.out.println("============localPath==========" + localPath);
                localRepo = new FileRepository(localPath + "/.git");
                git = new Git(localRepo);
                File localPathFile = new File(localPath);
                if (!localPathFile.exists()) {
                    gitClone(gitUrl, branch, localPath,credentialsProvider);
                } else {
                    gitPull(branch,credentialsProvider);
                }
            } catch (Exception e) {
                 e.printStackTrace();
            }
            return localPath;
        }



       */
/** 如果没有该代码目录,执行git clone
          *//*



        private void gitClone(String gitUrl, String branch, String localPath,UsernamePasswordCredentialsProvider credentialsProvider) throws Exception {
            Git.cloneRepository().setURI(gitUrl).setBranch(branch)
                    .setDirectory(new File(localPath))
                    .setCredentialsProvider(credentialsProvider).call();

        }


        */
/**
         *
         * 如果有代码,git pull
         *
         *//*



        private void gitPull(String branch,UsernamePasswordCredentialsProvider credentialsProvider) throws Exception {
            git.pull().setRemoteBranchName(branch).setCredentialsProvider(credentialsProvider).call();
        }

    }
*/
